{extend name="common/menu_child" /}

{block name="nav"}
<span class="layui-breadcrumb">
	<a>资源回收</a>
	<a href="{:url('index')}">工作人员</a>
	<a><cite>编辑地区</cite></a>
</span>
{/block}

{block name="body"}
<div class="layui-row">
	<form class="layui-form layui-col-md12 x-so">
		<input class="layui-input" placeholder="地区名称" name="title" value="{$condition.title}" autocomplete="off" />
		<input type="hidden" name="staff_id" value="{$staff_id}" />
		<button type="submit" class="layui-btn"><i class="layui-icon">&#xe615;</i></button>
		<button type="button" class="layui-btn layui-btn-normal submit_action">保存</button>
	</form>
</div>
<table class="layui-table" title="check_list">
	<thead>
		<tr>
			<th>
				<div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
			</th>
			<th>地区名称</th>
			<th>已绑定人数</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody>
		{empty name="region_list"}
		<tr>
			<td colspan="20">暂无相关数据</td>
		</tr>
		{else/}
		{foreach name="region_list" item="vo" key="ko"}
		<tr>
			<td>
				<div class="layui-unselect layui-form-checkbox {neq name='vo.is_checked' value='0'}layui-form-checked{/neq}" lay-skin="primary" data-id="{$vo.id}"><i class="layui-icon">&#xe605;</i></div>
			</td>
			<td>{$vo.name_full}</td>
			<td>{$vo.staff_count}</td>
			<td></td>
		</tr>
		{/foreach}
		{/empty}
	</tbody>
</table>
<div class="page">{$page}</div>
{/block}

{block name="javascript"}
<script type="text/javascript">
	
	layui.use(['form', 'layer'], function(){
		
		/** 提交执行 */
		$('button.submit_action').on('click', function(e){
			
			
			let message = '确认要进行此操作吗？';
			layer.confirm(message, {}, function(window_open){
				/** 准备数据 */
				let cancel_id = new Array();
				let checked_id = new Array();
				let select_list = $('div.layui-form-checkbox');
				for(let i = 0; i < select_list.length; i++){
					/** 判断是否存在数据 */
					let data_id = $(select_list[i]).attr('data-id');
					if(undefined === data_id){
						continue;
					};
					
					/** 根据是否选中分类整理数据 */
					data_id = parseInt(data_id)
					let judge = $(select_list[i]).attr('class').indexOf('layui-form-checked');
					if(0 < judge){
						checked_id.push(data_id);
					}else{
						cancel_id.push(data_id);
					};
				};
				
				/** 提交更改到远程服务 */
				let data = {
					cancel_id: cancel_id,
					checked_id: checked_id
				};
				action_post_json('', data, function(response){
					layer.msg(response.message);
					switch(response.errno){
						case 0 :
							setTimeout(function(){
								window.location.reload();
							}, 1000);
							break;
					};
				});
			});
		});
		
	});
	
</script>
{/block}